#!/bin/sh
#Copyright (C) 2020 iyfiysi
#gen by iyfiysi at {{ .CreateTime.Format "2006 Jan 02" }}

# pb构建
cd proto
sh gen.sh
cd -

statik -src ./swagger -f

BUILT_AT=$(date "+%Y-%m-%d %H:%M:%S") #2020-03-30 10:08:54
COMMIT_TAG=$(git rev-parse HEAD) #1c7caa847ce196f0668e01794d3cd773944f3127
if [ ${#COMMIT_TAG} -eq 40 ];then
    COMMIT_TAG=${COMMIT_TAG:0:8}
else
    COMMIT_TAG="unknow"
fi

eval $(go env)

# build gateway
cd cmd/gateway
go build -ldflags "-X 'main.commit=$COMMIT_TAG' -X 'main.date=$BUILT_AT'" -o {{.AppName}}_gateway .
#GOARCH=amd64 GOOS=darwin go build -ldflags "-X 'main.commit=$COMMIT_TAG' -X 'main.date=$BUILT_AT'" -o {{.AppName}}_gateway .
#GOARCH=amd64 GOOS=windows go build -ldflags "-X 'main.commit=$COMMIT_TAG' -X 'main.date=$BUILT_AT'" -o {{.AppName}}_gateway .
mv {{.AppName}}_gateway ../..
cd -

cd cmd/server
go build -ldflags "-X 'main.commit=$COMMIT_TAG' -X 'main.date=$BUILT_AT'" -o {{.AppName}}_server .
mv {{.AppName}}_server ../..
cd -

cd cmd/conf
go build -ldflags "-X 'main.commit=$COMMIT_TAG' -X 'main.date=$BUILT_AT'" -o {{.AppName}}_conf .
mv {{.AppName}}_conf ../..
cd -

#end
